<div class="content_wrapper">
  <div class="content_wrapper_inner">
    <script>
     $(document).ready(function(){
       $("#booknow").click(function(event){

    	   var $dep = $("input[name='sel_depart']:checked").val();
		   var $arr = $("input[name='sel_return']:checked").val();
			
			if ($dep == null) {
			 alert("<?php echo $this->lang->line('select_depart');?>");
	    	 event.preventDefault();
	         return;
			} 
	       	if ($("input[name='trip_type']:checked").val() == "RT" && $arr == null) {
				 alert("<?php echo $this->lang->line('select_return');?>");
		    	 event.preventDefault();
		         return;
	       	}
				
    	   	$dep = $("input[name='sel_depart']:checked").val().split('|');
			$arr = $("input[name='sel_return']:checked").val().split('|');

			var $dep_time=$dep[3];
         	if ($dep[0] == 2) {
          		$dep_time=$dep[9];
         	}
		 	if ($dep_time[2] == '-') {
		  		$dep_time=$dep_time.substr(3);
		 	}
			$dep_time = $dep_time.substr(0,2)+":"+$dep_time.substr(2)+":00";
			var str1 = $("input[name='depart_on']").val();
		    var dt1  = str1.substring(0,2);
		    var mon1 = str1.substring(3,5);
		    var yr1  = str1.substring(6,10);
		    temp1 = mon1 +"/"+ dt1 +"/"+ yr1 + " "+ $dep_time;
		    var $dep_flight = Date.parse(temp1);

			var $now = Date.now();	
			$diff = $dep_flight - $now;
		    if ($diff < 10900000) {
			 	alert("<?php echo $this->lang->line('flight_closed');?>");
			 	event.preventDefault();
		     	return;
			}
	    
		    var $arr_time=$arr[3];
			if ($arr_time[2] == '-') {
			  $arr_time=$arr_time.substr(3);
			}
			$arr_time = $arr_time.substr(0,2)+":"+$arr_time.substr(2)+":00";
		        
		    var str2 = $("input[name='return_on']").val();
		    var dt2  = str2.substring(0,2);
		    var mon2 = str2.substring(3,5);
		    var yr2  = str2.substring(6,10);
		    temp2 = mon2 +"/"+ dt2 +"/"+ yr2 + " "+ $arr_time;
		    var $arr_flight = Date.parse(temp2);
	
		    $diff = $arr_flight - $dep_flight;
		
		    if ($diff > 10800000 ) {
		         $("#bookflight").submit();
		    }
		    else {
				alert("<?php echo $this->lang->line('date_prior');?>");
		         event.preventDefault();
		    }
		});
    });

    $(document).ready(function(){
       $("#next_day_depart").click(function(event){
         $("input[name='depart_on']").val("<?php echo date("d.m.Y",strtotime(date("d-m-Y", strtotime($this->input->post('depart_on'))) . " +1 day"));?>");
         $("#searchflight").submit();
         event.preventDefault();
       });
     });
    $(document).ready(function(){
       $("#pre_day_depart").click(function(event){
         $("input[name='depart_on']").val("<?php echo date("d.m.Y",strtotime(date("d-m-Y", strtotime($this->input->post('depart_on'))) . " -1 day"));?>");
         $("#searchflight").submit();
         event.preventDefault();
       });
     });
    $(document).ready(function(){
        $("#next_day_return").click(function(event){
          $("input[name='return_on']").val("<?php echo date("d.m.Y",strtotime(date("d-m-Y", strtotime($this->input->post('return_on'))) . " +1 day"));?>");
          $("#searchflight").submit();
          event.preventDefault();
        });
      });
      $(document).ready(function(){
        $("#pre_day_return").click(function(event){
          $("input[name='return_on']").val("<?php echo date("d.m.Y",strtotime(date("d-m-Y", strtotime($this->input->post('return_on'))) . " -1 day"));?>");
          $("#searchflight").submit();
          event.preventDefault();
        });
    });	
    </script>


<script type="text/javascript">
$(function () {
	$('a[rel=TK]').mouseover(function(){
		var TK = '<div class="TK"><div class="tooltipust"></div><div class="tooltiporta">Turkish Airlines</div><div class="tooltipalt"></div></div>';
		var TKpozisyon = $(this).position();
		$(this).append(TK);
		var alanyukseklik = $(this).height();
		var toolgenislik = $('.TK').width();
		var alangenislik = $(this).width();
		var tooltipleft = (toolgenislik/2) - (alangenislik/2);
		$(this).append(TK);
		$('.TK').css('top', TKpozisyon.top - 40);
		$('.TK').css('left', TKpozisyon.left - tooltipleft - 1);
		$('.TK').hide();
		$('.TK').fadeIn('slow');
	}).mouseout(function(){
		$(this).children('div.TK').remove();
	});
});

$(function () {
	$('a[rel=AJ]').mouseover(function(){
		var AJ = '<div class="AJ"><div class="tooltipust"></div><div class="tooltiporta">Anadolu Jet</div><div class="tooltipalt"></div></div>';
		var AJpozisyon = $(this).position();
		$(this).append(AJ);
		var alanyukseklik = $(this).height();
		var toolgenislik = $('.AJ').width();
		var alangenislik = $(this).width();
		var tooltipleft = (toolgenislik/2) - (alangenislik/2);
		$(this).append(AJ);
		$('.AJ').css('top', AJpozisyon.top - 40);
		$('.AJ').css('left', AJpozisyon.left - tooltipleft - 1);
		$('.AJ').hide();
		$('.AJ').fadeIn('slow');
	}).mouseout(function(){
		$(this).children('div.AJ').remove();
	});
});

$(function () {
	$('a[rel=XQ]').mouseover(function(){
		var XQ = '<div class="XQ"><div class="tooltipust"></div><div class="tooltiporta">Sun Express</div><div class="tooltipalt"></div></div>';
		var XQpozisyon = $(this).position();
		$(this).append(XQ);
		var alanyukseklik = $(this).height();
		var toolgenislik = $('.XQ').width();
		var alangenislik = $(this).width();
		var tooltipleft = (toolgenislik/2) - (alangenislik/2);
		$(this).append(XQ);
		$('.XQ').css('top', XQpozisyon.top - 40);
		$('.XQ').css('left', XQpozisyon.left - tooltipleft - 1);
		$('.XQ').hide();
		$('.XQ').fadeIn('slow');
	}).mouseout(function(){
		$(this).children('div.XQ').remove();
	});
});

$(function () {
	$('a[rel=ertesi]').mouseover(function(){
		var ertesi = '<div class="ertesi"><div class="tooltipust"></div><div class="tooltiporta">Ertesi Gün</div><div class="tooltipalt"></div></div>';
		var ertesipozisyon = $(this).position();
		$(this).append(ertesi);
		var alanyukseklik = $(this).height();
		var toolgenislik = $('.ertesi').width();
		var alangenislik = $(this).width();
		var tooltipleft = (toolgenislik/2) - (alangenislik/2);
		$(this).append(ertesi);
		$('.ertesi').css('top', ertesipozisyon.top - 40);
		$('.ertesi').css('left', ertesipozisyon.left - tooltipleft - 1);
		$('.ertesi').hide();
		$('.ertesi').fadeIn('slow');
	}).mouseout(function(){
		$(this).children('div.ertesi').remove();
	});
});
</script>
<style>
.TK, .AJ, .XQ, .ertesi {
	text-align:center;
	position: absolute;
	top: -50px;
	left: 0;
	color: #FFF;
	font: 12px arial;
}

.tooltipust {
	background: url(../images/tmpl/toolalt.png) no-repeat;
	width: 100px;
	height: 8px;
}

.tooltipalt {
	background: url(../images/tmpl/toolust.png) no-repeat;
	width: 100px;
	height: 14px;
}

.tooltiporta {
	background: url(../images/tmpl/toolorta.png);
	width: 92px;
	padding: 0 4px;
}
</style>

	<?php $enable_https='http://'; /* to enable put s after http */
  	echo str_replace('http://',$enable_https , form_open('bookflight',array('id'=>'bookflight','method'=>'get'))); ?>
    <div class="depart">
		<div align="center" style="padding-right:30px">
			<h4><?php echo $this->lang->line('select_depart');?></h4>
		</div>
	<div style="text-align:center; padding-right:30px;">
		<button id="pre_day_depart"><?php echo $this->lang->line('previous_day');?></button>
		<span style="padding: 0 100px 0 100px;"><?php echo $this->input->post('depart_on'); ?></span>
		<button id="next_day_depart"><?php echo $this->lang->line('next_day');?></button>
	</div>
	  <?php
	    if (count($flight_depart) == 0){
        	echo '<div class="noFlight">'. $this->lang->line('no_available_flight_for_today') .'</div>';
      	} else {
      		?><br>
			<div class="showBox" style=";padding-left:0px;">
      		<table class="tb_available"> 
			<thead>
				<tr height="24">
					<th>Şirket<br/></th>
					<th>Güzergah</th>
					<th>Sefer</th>
					<th>Uçak tipi</th>
					<th>Kalkış</th>
					<th style="text-align:left;">Varış</th>
					<th>Prom./TL</th>
					<th>Ekon./TL</th>
					<th>Busin./TL</th>	
				</tr>
			</thead>
			<tbody>
      		<?php  
		    foreach($flight_depart as $flight_details)
			{
			   	$flight = $flight_details['flight'];
				$leg = '<tr height="35">
							<td style="width:30px; border-right:0px; border-left:0px; text-align:center;">
								<a rel="'.$flight['leg1']["operatingairline"].'">
									<img src="/images/logo_'.$flight['leg1']["operatingairline"].'.png" />
								</a>
							</td>
							<td style="width:75px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']["origin"] .' - '. $flight['leg1']["destination"] .'
							</td>
							<td style="width:60px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']['flightno'] .'
							</td>
							<td style="width:60px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']['crafttype'] .'
							</td>
							<td style="width:50px; border-right:0px; border-left:0px; text-align:center;">
								'. $this->commonlibrary->format_flighttime($flight['leg1']["departureTime"]) .'
							</td>
							<td style="width:80px; text-align:left; border-right:0px; border-left:0px;">
							'. $this->commonlibrary->format_flighttime($flight['leg1']["arrivalTime"]) .' 
							<a rel="ertesi">'. $flight['leg1']['nextDay'].'</a>
							</td>';
				
				if (isset($flight['leg2'])) {
				$leg = '<tr height="45">
							<td style="width:30px; border-right:0px; border-left:0px; text-align:center;">
								<a rel="'.$flight['leg1']["operatingairline"].'"><img src="/images/logo_'.$flight['leg1']["operatingairline"].'.png" /></a><br/>
								<a rel="'.$flight['leg2']["operatingairline"].'"><img src="/images/logo_'.$flight['leg2']["operatingairline"].'.png" /></a>
							</td>
							<td style="width:75px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']["origin"] .' - '. $flight['leg1']["destination"] .'<br>
								'. $flight['leg2']['origin'] .' - '. $flight['leg2']["destination"] .'
							</td>
							<td style="width:60px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']['flightno'] .'<br>
								'. $flight['leg2']['flightno'] .'
							</td>
							<td style="width:60px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']['crafttype'] .'<br>
								'. $flight['leg2']['crafttype'] .'
							</td>
							<td style="width:50px; border-right:0px; border-left:0px; text-align:center;">
								'. $this->commonlibrary->format_flighttime($flight['leg1']["departureTime"]) .'<br>
								'. $this->commonlibrary->format_flighttime($flight['leg2']["departureTime"]) .'
							</td>
							<td style="width:80px; text-align:left; border-right:0px; border-left:0px;">
								'. $this->commonlibrary->format_flighttime($flight['leg1']["arrivalTime"]) .'
								<a rel="ertesi">'. $flight['leg1']['nextDay'].'</a><br>
								'. $this->commonlibrary->format_flighttime($flight['leg2']["arrivalTime"]) .' 
								<a rel="ertesi">'. $flight['leg2']['nextDay'].'</a>
							</td>
						';
				}
			   	
			   	?>
	               <?php echo $leg;?> 
						<td class="cost" style="padding:0 10px 0 0;"> <?php echo ($flight_details['total_amount_ecr'] != 0) ? number_format($flight_details['total_amount_ecr']).'<input type="radio" value="'.$flight_details['key_ecr'].'" name="sel_depart">'  : '-' ;?></td>
						<td class="cost" style="padding:0 10px 0 0;"> <?php echo ($flight_details['total_amount_eco'] != 0) ? number_format($flight_details['total_amount_eco']).'<input type="radio" value="'.$flight_details['key_eco'].'" name="sel_depart">' : '-' ;?></td>	
						<td class="cost" style="padding:0 10px 0 0;"> <?php echo ($flight_details['total_amount_bus'] != 0) ? number_format($flight_details['total_amount_bus']).'<input type="radio" value="'.$flight_details['key_bus'].'" name="sel_depart">' : '-' ;?></td>
					</tr>
				<?php           
	        }
	        ?>
	        </tbody>
	        </table>
	        <?php
      	}
	 ?>
	</div><br><br>
    <?php if(strcmp($this->input->post('trip_type'),'RT')==0){?> <!-- TODO: check whether is return availability -->
		<div class="return">
			<div style="text-align:center; padding-right:30px;">
				<h4><?php echo $this->lang->line('select_return');?></h4>
			</div>
		<div style="text-align:center;  padding-right:30px;">
			<button id="pre_day_return"><?php echo $this->lang->line('previous_day');?></button>
			<span style="padding: 0 100px 0 100px;"><?php echo $this->input->post('return_on'); ?></span>
			<button id="next_day_return"><?php echo $this->lang->line('next_day');?></button>
		</div>
		<?php
	    if (count($flight_return) == 0){
        	echo '<div class="noFlight">'. $this->lang->line('no_available_flight_for_today') .'</div>';
      	} else {
      		?><br>
			<div class="showBox" style="padding-left:0px;">
      		<table class="tb_available"> 
			<thead>
				<tr height="24">
					<th>Şirket<br/></th>
					<th>Güzergah</th>
					<th>Sefer</th>
					<th>Uçak tipi</th>
					<th>Kalkış</th>
					<th style="text-align:left;">Varış</th>
					<th>Prom./TL</th>
					<th>Ekon./TL</th>
					<th>Busin./TL</th>	
				</tr>
			</thead>
			<tbody>
      		<?php  
		    foreach($flight_return as $flight_details)
			{
			   	$flight = $flight_details['flight'];
				$leg = '<tr height="35">
							<td style="width:30px; border-right:0px; border-left:0px; text-align:center;">
								<a rel="'.$flight['leg1']["operatingairline"].'">
									<img src="/images/logo_'.$flight['leg1']["operatingairline"].'.png" />
								</a>
							</td>
							<td style="width:75px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']["origin"] .' - '. $flight['leg1']["destination"] .'
							</td>
							<td style="width:60px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']['flightno'] .'
							</td>
							<td style="width:60px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']['crafttype'] .'
							</td>
							<td style="width:50px; border-right:0px; border-left:0px; text-align:center;">
								'. $this->commonlibrary->format_flighttime($flight['leg1']["departureTime"]) .'
							</td>
							<td style="width:80px; text-align:left; border-right:0px; border-left:0px;">
							'. $this->commonlibrary->format_flighttime($flight['leg1']["arrivalTime"]) .' 
							<a rel="ertesi">'. $flight['leg1']['nextDay'].'</a>
							</td>';
				
				if (isset($flight['leg2'])) {
				$leg = '<tr height="45">
							<td style="width:30px; border-right:0px; border-left:0px; text-align:center;">
								<a rel="'.$flight['leg1']["operatingairline"].'"><img src="/images/logo_'.$flight['leg1']["operatingairline"].'.png" /></a><br>
								<a rel="'.$flight['leg2']["operatingairline"].'"><img src="/images/logo_'.$flight['leg2']["operatingairline"].'.png" /></a>
							</td>
							<td style="width:75px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']["origin"] .' - '. $flight['leg1']["destination"] .'<br>
								'. $flight['leg2']['origin'] .' - '. $flight['leg2']["destination"] .'
							</td>
							<td style="width:60px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']['flightno'] .'<br>
								'. $flight['leg2']['flightno'] .'
							</td>
							<td style="width:60px; border-right:0px; border-left:0px; text-align:center;">
								'. $flight['leg1']['crafttype'] .'<br>
								'. $flight['leg2']['crafttype'] .'
							</td>
							<td style="width:50px; border-right:0px; border-left:0px; text-align:center;">
								'. $this->commonlibrary->format_flighttime($flight['leg1']["departureTime"]) .'<br>
								'. $this->commonlibrary->format_flighttime($flight['leg2']["departureTime"]) .'
							</td>
							<td style="width:80px; text-align:left; border-right:0px; border-left:0px;">
								'. $this->commonlibrary->format_flighttime($flight['leg1']["arrivalTime"]) .' 
								<a rel="ertesi">'. $flight['leg1']['nextDay'].'</a><br>
								'. $this->commonlibrary->format_flighttime($flight['leg2']["arrivalTime"]) .' 
								<a rel="ertesi">'. $flight['leg2']['nextDay'].'</a>
							</td>
						';
				}
			   	
			   	?>
	               <?php echo $leg;?> 
						<td class="cost" style="padding:0 10px 0 0;"> <?php echo ($flight_details['total_amount_ecr'] != 0) ? number_format($flight_details['total_amount_ecr']).'<input type="radio" value="'.$flight_details['key_ecr'].'" name="sel_return">'  : '-' ;?></td>
						<td class="cost" style="padding:0 10px 0 0;"> <?php echo ($flight_details['total_amount_eco'] != 0) ? number_format($flight_details['total_amount_eco']).'<input type="radio" value="'.$flight_details['key_eco'].'" name="sel_return">' : '-' ;?></td>	
						<td class="cost" style="padding:0 10px 0 0;"> <?php echo ($flight_details['total_amount_bus'] != 0) ? number_format($flight_details['total_amount_bus']).'<input type="radio" value="'.$flight_details['key_bus'].'" name="sel_return">' : '-' ;?></td>
					</tr>
				<?php           
	        }
	        ?>
	        </tbody>
	        </table>
	        <?php
			}
			?>
			</div>
		</div>
	<?php }?>
		<div class="bookButton"><br>
			<button id="booknow" style="width:150px;"><?php echo $this->lang->line('continue');?></button>
		</div>
	<?php echo form_close();?>
		</div>
	</div>
</div>